package sbc.ejb3.dao;

import javax.ejb.EJB;
import javax.persistence.PostPersist;
import javax.persistence.PostUpdate;

import org.apache.log4j.Logger;

import sbc.ejb3.Messung;
import sbc.ejb3.Platine;
import sbc.ejb3.Sensor;

public class CallbackHandler {
	
	private static Logger log = Logger.getLogger(CallbackHandler.class);
	
	@EJB private DistributorRemote distributor;
	
	@PostPersist void postPersist(Object entity) {
		if (entity instanceof Platine) {
			log.info("Platine " + entity + " persisted");
			
			//distributor.forwardToMontageTopic();				
		}
		else if (entity instanceof Sensor) {
			log.info("Sensor " + entity + " persisted");
			
			//distributor.forwardToQsTopic();			
		}
		else if (entity instanceof Messung) {
			log.info("Messung " + entity + " persisted");
			
		}
	}

	@PostUpdate void postUpdate(Object entity) {	
		if (entity instanceof Platine) {
			log.info("Platine " + entity + " updated");
			
			//distributor.forwardToLogisticQueue();				
		}
		else if (entity instanceof Sensor) {
			log.info("Sensor " + entity + " updated");
			
			//distributor.forwardToMontageTopic();			
		}
		else if (entity instanceof Messung) {
			log.info("Messung " + entity + " updated");
			
		}
	}
}
